from hx711 import HX711
from machine import Pin,SPI
import dht

global driver1
global g0
driver1 = HX711(pd_sck=47,d_out=48)
g0 = int(int(driver1.read())/442)
def read_hx711():
    global driver1
    re = "重量" + str(-int(int(int(driver1.read())/442)-g0))+"g"
    #print(re)
    return(re)

global driver2
driver2 = dht.DHT11(Pin(35))
def read_dht11():
    global driver2
    driver2.measure()
    temp = driver2.temperature() # eg. 23 (°C)
    RH = driver2.humidity()    # eg. 41 (% RH)
    data = "温度:%s℃ ; 湿度: %sRH" % (driver2.temperature(), driver2.humidity())
    #print(data)
    return(data)

def ep():
    print("开始运行")
    return("欢迎使用树莓派下位机！")

while True:
    input_data = input()
    msgo = ""
    try:
        msgo = msgo + read_dht11()
    except:
        msgo = msgo + "dht11错误"
    msgo = msgo + " // "
    try:
        msgo = msgo + read_hx711()
    except:
        msgo = msgo + "重量传感器错误"
    print(msgo)
    #exec(input_data)